package com.example.redisdemo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Created by bruce on 2022/11/11.
 */
@RestController
public class RedisController {
    @Resource
    StringRedisTemplate stringRedisTemplate;

    @Autowired(required = false)
    @GetMapping("redis/setvalue")
    public String setValue(){
        String key = "xiaozhang";
        String value="23";

        stringRedisTemplate.opsForValue().set(key,value);
        return "set successfully";
    }

    @GetMapping("redis/getvalue")
    public String getValue(){
        String key = "xiaozhang";
        String str = stringRedisTemplate.opsForValue().get(key);
        return str;
    }
}
